package org.finesys.chat.core.base.embedding.store.pgvector;

import java.util.Collections;
import java.util.List;

import org.finesys.chat.core.base.embedding.store.pgvector.constants.MetadataStorageMode;

import lombok.NonNull;

public class DefaultMetadataStorageConfig implements MetadataStorageConfig {
    private @NonNull MetadataStorageMode storageMode;
    private @NonNull List<String> columnDefinitions;
    private List<String> indexes;
    private String indexType;


    public DefaultMetadataStorageConfig(@NonNull MetadataStorageMode storageMode, @NonNull List<String> columnDefinitions, List<String> indexes, String indexType) {
        if (storageMode == null) {
            throw new NullPointerException("storageMode is marked non-null but is null");
        } 
        if (columnDefinitions == null) {
            throw new NullPointerException("columnDefinitions is marked non-null but is null");
        } 
        this.storageMode = storageMode;
        this.columnDefinitions = columnDefinitions;
        this.indexes = indexes;
        this.indexType = indexType;
    }

    public static MetadataStorageConfig defaultConfig() {
        return builder().storageMode(MetadataStorageMode.COMBINED_JSON).columnDefinitions(Collections.singletonList("metadata JSON NULL")).build();
    }

    public static Builder builder() {
        return new Builder();
    }

    @Override
    public MetadataStorageMode storageMode() {
        return this.storageMode;
    }

    @Override
    public List<String> columnDefinitions() {
        return this.columnDefinitions;
    }

    @Override
    public List<String> indexes() {
        return this.indexes;
    }

    @Override
    public String indexType() {
        return this.indexType;
    }

    public static class Builder {

        private @NonNull MetadataStorageMode storageMode;
        private @NonNull List<String> columnDefinitions;
        private List<String> indexes;
        private String indexType;

        public Builder storageMode(MetadataStorageMode mode) {
            this.storageMode = mode;
            return this;
        }

        public Builder columnDefinitions(List<String> definitions) {
            this.columnDefinitions = definitions;
            return this;
        }

        public Builder indexes(List<String> indexes) {
            this.indexes = indexes;
            return this;
        }

        public Builder indexType(String type) {
            this.indexType = type;
            return this;
        }

        public DefaultMetadataStorageConfig build() {
            return new DefaultMetadataStorageConfig(this.storageMode, this.columnDefinitions, this.indexes, this.indexType);
        }
    }
}